package pl.ydp.components.mathcell.mathrecognizer.model
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import pl.ydp.components.mathcell.mathrecognizer.engine.Parameters;
	import pl.ydp.components.mathcell.mathrecognizer.geometry.PrimitiveStructure;
	
	public class PrimitiveModel extends PrimitiveStructure
	{
		
		private const __DEFAULT:Number = -99999999;
		
		public static const NONE:Number = -1;
		
		//------------------------------------------------------------------
		
		public function PrimitiveModel(_field:Rectangle, _positioning:Number, _cog_x:Number = __DEFAULT, _cog_y:Number = __DEFAULT)
		{
			field = _field.clone();
			positioning = _positioning;
			
			if (_cog_x == __DEFAULT  &&  _cog_y == __DEFAULT){
				cog = new Point(field.x + field.width/2,field.y + field.height/2);  	
			} else{
				cog = new Point(_cog_x, _cog_y);	
			}
			
		}
		
		//------------------------------------------------------------------
		
		public var positioning:Number;
		
		
		//------------------------------------------------------------------
		
		public function clone():PrimitiveModel{
			return new PrimitiveModel(field, positioning);
			
		}
		
		public function cloneResized(shapeField:Rectangle):PrimitiveModel{
			var pm:PrimitiveModel = new PrimitiveModel(field, positioning);
			
			if (positioning == PrimitiveModelPositioning.ABSOLUTE){
				
				var W:Number = Parameters.CHAR_NORMALIZED_WIDTH;
				var H:Number = Parameters.CHAR_NORMALIZED_HEIGHT;
				
				pm.cog.x *= W;
				pm.cog.y *= H;
				 
				pm.field = new Rectangle(field.x*W, field.y*H, field.width*W, field.height*H);
				
			} else if (positioning == PrimitiveModelPositioning.RELATIVE){
				pm.cog.x = (pm.cog.x * shapeField.width) + shapeField.x;
				pm.cog.y = (pm.cog.y * shapeField.height) + shapeField.y;
				
				pm.field = new Rectangle ( field.x * shapeField.width + shapeField.x, 
										field.y * shapeField.height + shapeField.y, 
										field.width * shapeField.width, 
										field.height * shapeField.height);
			}
			
			return pm;
		}
		
		
		
	}
}